﻿// The Nova Project by Ken Beckett.
// Copyright (C) 2007-2012 Inevitable Software, all rights reserved.
// Released under the Common Development and Distribution License, CDDL-1.0: http://opensource.org/licenses/cddl1.php

using System.Collections.Generic;

using Nova.CodeDOM;

namespace Nova.UI
{
    /// <summary>
    /// The view model for a <see cref="CodeDOM.DocCDATA"/>.
    /// </summary>
    public class DocCDATAVM : DocCommentVM
    {
        #region /* STATICS */

        internal static new void AddViewModelMapping()
        {
            CreateViewModel.Add(typeof(DocCDATA),
                delegate(CodeObject codeObject, bool isDescription, Dictionary<CodeObject, CodeObjectVM> dictionary) { return new DocCDATAVM((DocCDATA)codeObject, dictionary); });
        }

        #endregion

        #region /* CONSTRUCTORS */

        /// <summary>
        /// Create a view model instance for the specified <see cref="CodeDOM.DocCDATA"/>.
        /// </summary>
        public DocCDATAVM(DocCDATA docCDATA, Dictionary<CodeObject, CodeObjectVM> dictionary)
            : base(docCDATA, dictionary)
        { }

        #endregion

        #region /* PROPERTIES */

        /// <summary>
        /// The underlying <see cref="CodeDOM.DocCDATA"/> model.
        /// </summary>
        public DocCDATA DocCDATA
        {
            get { return (DocCDATA)CodeObject; }
        }

        #endregion

        #region /* RENDERING */

        protected override void RenderStart(CodeRenderer renderer, RenderFlags flags)
        {
            if (!UseAlternativeFormat && (!flags.HasFlag(RenderFlags.Description) || DocCDATA.MissingEndTag))
                renderer.RenderText("<" + DocCDATA.ParseToken, DocCDATA.MissingEndTag ? WARNING_BRUSH : COMMENT_TAG_BRUSH, this);
        }

        protected override void RenderContent(CodeRenderer renderer, TextStyle textStyle, RenderFlags flags)
        {
            DocTextVM.RenderText(renderer, GetContentForDisplay(flags | (UseAlternativeFormat ? RenderFlags.NoTagNewLines : 0)), textStyle | TextStyle.NoCache, flags, this);
        }

        protected override void RenderEnd(CodeRenderer renderer, RenderFlags flags)
        {
            if (!DocCDATA.MissingEndTag && !flags.HasFlag(RenderFlags.Description) && !UseAlternativeFormat)
                renderer.RenderText(DocCDATA.ParseTokenClose, COMMENT_TAG_BRUSH, this);
        }

        #endregion
    }
}
